package com.twu.biblioteca;

public class UserLoginOption implements CustomerOptionHandler {
    private Library library;

    public UserLoginOption(Library library) {

        this.library = library;
    }

    @Override
    public String customerOption() {
        User user = library.getUser();
        if(user.hasLoggedIn()){
            return logout(user);
        }
        return login(user);
    }

    public String login(User user) {
        if(user.getUsername().equals(library.requestUsername()) && user.getPassword().equals(library.requestPassword())){
            user.checkIn();
            return "Logged in successfully";
        } else {
            return "Wrong login detail!!";
        }
    }

    public String logout(User user) {
        user.checkOut();
        return "You have logged out successfully";
    }
}
